<template>
  <a-modal
    v-model:visible="abnormalVisible"
    title="其他教师重评"
    :width="400"
    @ok="handleSignAbnormal"
  >
    <div style="padding: 20px">
      <a-row align="middle">
        <div class="w-full">
          <a-radio-group v-model:value="isFixTeacher">
            <!-- <a-radio :value="1">随机分配</a-radio> -->
            <a-radio :value="2">指定教师</a-radio>
          </a-radio-group>
        </div>
        <a-row v-if="isFixTeacher == 2" class="pt-10px w-full">
          <a-col :span="24" class="flex w-full">
            <label>重评教师：</label>
            <a-select
              v-model:value="formTeacher.distributeUserId"
              placeholder="请选择其他教师"
              :options="techantLentgh"
              style="width: calc(100% - 80px)"
            />
          </a-col>
        </a-row>
      </a-row>
    </div>
  </a-modal>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMessage } from '/@/hooks/web/useMessage'
import { reviewCompletedReevaluationTeacher } from '/@/api/teacher'
import { useRoute } from 'vue-router'
import { getHasTeachee } from '/@/api/organization/subjectManage'

const route = useRoute()
const { createMessage } = useMessage()
const props = defineProps({
  abnormalVisible: {
    type: Boolean,
    default: false,
  },
  currentTableRow: {
    type: Object,
    default: () => {},
  },
})

const emit = defineEmits(['success'])

const isFixTeacher = ref(2)
const formTeacher = ref({ distributeUserId: undefined })
// 其他教师重评
const techantLentgh = ref<any[]>([])

// 重评确认提交
const handleSignAbnormal = () => {
  if (!formTeacher.value.distributeUserId) {
    createMessage.warning('请选择重评教师!')
    return
  }
  reviewCompletedReevaluationTeacher({
    kmpyzt: route.query.kmpyzt,
    lsDfJlId: props.currentTableRow.id,
    userId: formTeacher.value.distributeUserId,
    kmDm: props.currentTableRow.kmdm,
  }).then(res => {
    if (res.code === 200) {
      createMessage.success('处理成功')
      formTeacher.value.distributeUserId = undefined
    }
    emit('success')
  })
}

const getAbnorList = async () => {
  const { data, code } = await getHasTeachee({ kmdm: route.query.kmdm })
  if (code === 200) {
    techantLentgh.value = []
    for (let key in data) {
      techantLentgh.value.push({
        label: `(${data[key]})${key}`,
        value: key,
      })
    }
  }
}

onMounted(() => {
  getAbnorList()
})
</script>

<style lang="less" scoped></style>
